<?php
namespace Rate\Controller;
use Todo\Controller\BackendController;
use Todo\Service\DictService;

class StaticsController extends BackendController {
    public function results(){
        $projectId = I('get.project_id/d',0);
        if($projectId){
            $sql = 'SELECT level,count(id) total from rate_results where project_id='. $projectId. ' group by level order by level';
            $list = M()->query($sql);
            $levels = DictService::getInstance()->getDict('SCORE_LEVEL');
            $map = $levels['map'];
            asort($map);
            $series = array();
            foreach ($map as $k=>$v){
                foreach ($list as $row){
                    if($row['level'] == $k){
                        $series[$k] = array('value'=>$row['total'], 'name'=>$v);
                        break;
                    }
                }
                if(!$series[$k]) $series[$k]= array('value'=>0, 'name'=>$v);
            }
            $data = array(
                'legend' => array_values($map),
                'series' => array_values($series)
            );
            $this->assign('data', $data);
        }

        $this->display();
    }
}